package com.heima.article.task;

import com.heima.article.service.IHotArticleService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 定时任务：计算最近5天发布文章的得分，将文章缓存到redis中
 */
@Slf4j
@Component
public class RecentHotArticle {


    @Autowired
    private IHotArticleService hotArticleService;

    /**
     * 定时计算文章分值的任务
     *
     * @return
     */
    @XxlJob("computeHotArticleJob")
    public ReturnT<String> computeHotArticleJob() {
        try {
            log.info("【文章微服务】定时计算热点文章任务执行了");
            hotArticleService.compute();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ReturnT.FAIL;
        }
    }
}
